﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;

namespace BlogElements.Models
{
    public class SampleData : DropCreateDatabaseIfModelChanges<BlogElementsEntities>
    {
        protected override void Seed(BlogElementsEntities context)
        {
            var tags = new List<Tag>
            {
                new Tag {TagId = 1, Name = "ASP.NET"},
                new Tag {TagId = 2, Name = "C#"},
                new Tag {TagId = 3, Name = "jquery"},
                new Tag {TagId = 4, Name = "css"},
                new Tag {TagId = 5, Name = "css3"},
                new Tag {TagId = 6, Name = "html"},
                new Tag {TagId = 7, Name = "html5"},
                new Tag {TagId = 8, Name = "slicing"},
                new Tag {TagId = 9, Name = "javascript"},
            };
            
            var posts = new List<Post>
            {
                new Post {PostId = 1, Title = "ASP.NET, C#, jquery post", DateCreated = DateTime.Parse("2007-01-01"), Description = "ASP.NET, C#, jquery Description", Body = "ASP.NET, C#, jquery Body"},
                new Post {PostId = 2, Title = "ASP.NET post 2", DateCreated = DateTime.Parse("2009-01-01"), Description = "ASP.NET post 2 Description", Body = "ASP.NET post 2 Body"  },
                new Post {PostId = 3, Title = "ASP.NET post 3", DateCreated = DateTime.Parse("2011-01-01"), Description = "ASP.NET post 3 Description", Body = "ASP.NET post 3 Body"  },
                new Post {PostId = 4, Title = "Jquery 2", DateCreated = DateTime.Parse("2012-01-01"), Description = "Jquery 2 Description", Body = "Jquery 2 Body"  },
            };

            new List<PostTag>
            {
                new PostTag {PostTagId = 1, PostId = 1, TagId = 1, Post = posts.Single(g => g.PostId == 1), Tag = tags.Single(g => g.TagId == 1)},
                new PostTag {PostTagId = 2, PostId = 1, TagId = 2, Post = posts.Single(g => g.PostId == 1), Tag = tags.Single(g => g.TagId == 2)},
                new PostTag {PostTagId = 3, PostId = 1, TagId = 3, Post = posts.Single(g => g.PostId == 1), Tag = tags.Single(g => g.TagId == 3)},
                new PostTag {PostTagId = 4, PostId = 2, TagId = 1, Post = posts.Single(g => g.PostId == 2), Tag = tags.Single(g => g.TagId == 1)},
                new PostTag {PostTagId = 5, PostId = 3, TagId = 1, Post = posts.Single(g => g.PostId == 3), Tag = tags.Single(g => g.TagId == 1)},
                new PostTag {PostTagId = 6, PostId = 4, TagId = 3, Post = posts.Single(g => g.PostId == 4), Tag = tags.Single(g => g.TagId == 3)},
            }.ForEach(a => context.PostTags.Add(a));
        }
    }
}